package com.xxx.modules;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

public class email {
    public static void main(String[] args) throws MessagingException {

        // map
        Properties pro = new Properties();
        pro.put("mail.transport.protocol","smtp");
        pro.put("mail.smtp.host","smtp.qq.com");
        // 建立连接
        Session session = Session.getInstance(pro);
        // 模拟对象
        MimeMessage message = new MimeMessage(session);
        // 发件人，收件人，时间，正文
        message.setFrom(new InternetAddress("2799594324@qq.com"));
        message.setRecipients(MimeMessage.RecipientType.TO, String.valueOf(new InternetAddress("2799594324@qq.com")));
        message.setSubject("qqqqq");
        message.setSentDate(new Date());
        message.setText("qqqq");
        message.saveChanges();

        //发
        Transport transport = session.getTransport();
        transport.connect("2799594324@qq.com","uellzpskzzzqdfab");
        transport.sendMessage(message,message.getAllRecipients());
        // 关闭
        transport.close();
    }
}
